//
//  FirstView.m
//  UIComprehensive
//
//  Created by lanou3g on 16/1/25.
//  Copyright © 2016年 徐强. All rights reserved.
//

#import "FirstView.h"

@implementation FirstView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self addAllView];
    }
    return self;
}

- (void)addAllView{
    
#pragma mark - UILabel
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(50, 50, 100, 50)];
    //背景颜色
    label.backgroundColor = [UIColor redColor];
    label.text = @"第一个label";
    //字体颜色
    label.textColor = [UIColor yellowColor];
    //对其方式
    label.textAlignment = NSTextAlignmentCenter;
    //换行:自动换行
    label.numberOfLines = 0;
    //断行方式
    /*
     NSLineBreakByTruncatingHead,	// Truncate at head of line: "...wxyz"
     NSLineBreakByTruncatingTail,	// Truncate at tail of line: "abcd..."
     NSLineBreakByTruncatingMiddle	// Truncate middle of line:  "ab...yz"
     */
    label.lineBreakMode = NSLineBreakByCharWrapping;
    //阴影
    //阴影颜色
    label.shadowColor = [UIColor greenColor];
    //阴影的偏移量
    label.shadowOffset = CGSizeMake(10, 10);
    //加圆弧
    label.layer.cornerRadius = 5 ;
    label.layer.borderWidth = 2;
    label.layer.borderColor = [UIColor redColor].CGColor;
    //剪裁
    label.layer.masksToBounds = YES;
    
    [self addSubview:label];
    
#pragma mark - UIView
    UIView *redView = [[UIView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(label.frame)+20, 50, 100, 50)];
    redView.backgroundColor = [UIColor redColor];
    //透明度
    redView.alpha = 0.2;
    //tag：系统占用100以前的tag，所以从101开始写
    redView.tag = 101;
    //是否隐藏
    redView.hidden = NO;
    [self addSubview:redView];
    
    UIView *blueView = [[UIView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(label.frame)+20, 50, 50, 100)];
    blueView.backgroundColor = [UIColor blueColor];
    [self addSubview:blueView];
    
    UIView *cyanView = [[UIView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(label.frame)+20, 50, 75, 75)];
    cyanView.backgroundColor = [UIColor cyanColor];
    [self addSubview:cyanView];
    
    //对3个View的上下位置进行排序
    [self insertSubview:cyanView atIndex:0];
    [self insertSubview:redView aboveSubview:blueView];
//    //移除view
//    [cyanView removeFromSuperview];
    //改变父视图颜色
    blueView.superview.backgroundColor = [UIColor grayColor];
    
#pragma mark - UIButton
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setFrame:CGRectMake(CGRectGetMinX(label.frame), CGRectGetMaxY(label.frame)+20, 80, 40)];
    [button setBackgroundColor:[UIColor purpleColor]];
    //UIControlStateNormal     未点击状态
    //UIControlStateHighlighted 点击状态
    [button setTitle:@"第一个Button" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    //也能表示button的两种状态
    button.selected = YES;
    //button特性:点击按钮一次，执行一次方法
    [button addTarget:self  action:@selector(actionButton:) forControlEvents:UIControlEventTouchUpInside];
    
#pragma mark - UITextField
    
    UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(CGRectGetMinX(blueView.frame), CGRectGetMaxY(blueView.frame)+20, 100, 40)];
    //边框样式
    textField.borderStyle = UITextBorderStyleRoundedRect;
    //占位符
    textField.placeholder = @"请输入文字";
    //密文输入
    textField.secureTextEntry = YES;
    //清除按钮
    textField.clearButtonMode = UITextFieldViewModeWhileEditing;
    //文本框能否输入
    textField.enabled = YES;
    /*
     一些不常用的属性：
     keyboardType:键盘样式（枚举值）
     returnKeyType:return键样式（枚举值）
     inputAccessoryView:键盘上方的辅助视图
     leftView/rightView:文本框左右的显示的一个小view（必须设置显示模式）：UITextFieldViewModeAlways
     */
    /*
     代理:UITextFieldDelegate(遵循协议)
     设置代理
     实现方法:键盘回首：- (BOOL)textFieldShouldReturn:(UITextField *)textField{  
                // 点击return键回首键盘
                [textField resignFirstResponder];
                return YES;
            }
     */
    [self addSubview:textField];
#pragma mark - UISlider
    UISlider *slider = [[UISlider alloc]initWithFrame:CGRectMake(CGRectGetMinX(label.frame), CGRectGetMaxY(label.frame)+40, 200, 30)];
    slider.backgroundColor = [UIColor greenColor];
    //min：滑块左边线条的颜色
    slider.minimumTrackTintColor = [UIColor redColor];
    //max：滑块右边线条的颜色
    slider.maximumTrackTintColor = [UIColor purpleColor];
    //滑块的颜色
    slider.thumbTintColor = [UIColor blackColor];
//    //滑块当前的位置：value默认为0-1
//    slider.value = 0.3;
    //滑块最大、最小值
    slider.maximumValue = 100;
    slider.minimumValue =10;
    slider.value = 20;
    //左右图标：minimumValueImage，maximumValueImage
    //
    [slider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
    [self addSubview:slider];
#pragma mark - UISegmentedControl
    //参数是一个数组
    UISegmentedControl *segment = [[UISegmentedControl alloc]initWithItems:@[@"第一栏",@"第二栏",@"第三栏"]];
    segment.frame = CGRectMake(0, CGRectGetMaxY(textField.frame)+20, kScreenWidth, 40);
    segment.backgroundColor = [UIColor brownColor];
//    //插入两栏
//    [segment insertSegmentWithTitle:@"特别栏" atIndex:1 animated:NO];
//    [segment insertSegmentWithImage:[[UIImage imageNamed:@"2.jpg"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ]atIndex:1 animated:YES];
    //改变选中时的颜色
    segment.tintColor = [UIColor redColor];
    //添加点击事件方法
    [segment addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
    [self addSubview:segment];
#pragma mark - 自学
/*
 1.UIProgressView进度条控件
 2.UIActivityIndicatorView缓冲动画
 3.UIActionSheet,UIAlertView;UIAlertContrller
 4.UITextView（类比与UITextField：可编辑，遵守协议，回收键盘等，）
 5.UISwitch
 6.UIStepper
 */
}
- (void)segmentAction:(UISegmentedControl *)sender{
    //selectedSegmentIndex选中图标的下标
    switch (sender.selectedSegmentIndex) {
        case 0:
        {
            
        }
            break;
        case 1:
        {
            
        }
            break;
        case 2:
        {
            
        }
            break;
            
        default:
            break;
    }
}

- (void)sliderAction:(UISlider *)sender{
    NSLog(@"滑块的位置%.2f",sender.value);
}
- (void)actionButton:(UIButton *)sender{
    sender.selected = !sender.selected;
    [sender setTitle:(sender.selected ? @"已点击" : @"未点击") forState:UIControlStateNormal];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
